<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>老师端提问列表</title>
		<link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css">
		<link rel="stylesheet" href="../../css/weui.min.css">
		<style>
			body {
			}
			.mui-table-view-cell:active {
				background: #fff;
			}
			.mui-table-view-cell > a:not(.mui-btn) {
				padding: 10px;
			}
			.cell-title {
				height: 22px;
			}
			.cell-subtitle, .message_content {
				height: 20px;
			}
			.right-div {
				width: 70px;
				float: right;
			}
			.left-div {
				margin-right: 70px;
			}
			.message_title {
				width: 90%;
				color: #222222
			}
			.right-tag {
				text-align: right;
			}
			.mui-table-view .mui-media-object {
				/*margin-top: 10px;*/
			}
			.discuss-del {
				width: 18px;
				margin-right: 0px;
			}
			.discuss-del-div {
				text-align: right;
				height: 24px;
				padding-top: 4px;
			}
			.popu_img {
				height: 20px;
				width: 20px;
			}
		</style>
	</head>
	<body>
		<div id="mian">
			<ul id="list_day" class="mui-table-view" >
				<!-- <li class="mui-table-view-cell mui-media" where_type="0" id="7043" onclick="openwin(this,{&quot;template&quot;:1,&quot;id&quot;:7043,&quot;name&quot;:&quot;调查-20180806036&quot;,&quot;num&quot;:0,&quot;countnum&quot;:0,&quot;tid&quot;:3,&quot;createtime&quot;:&quot;1533548351&quot;,&quot;status&quot;:0})"><a href="javascript:;" )"><img class="mui-media-object mui-pull-left" src="../../icon/icon_research.png" ><div class="mui-media-body"><div class="right-div"><div class="discuss-del-div"><img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(0,0,{&quot;template&quot;:1,&quot;id&quot;:7043,&quot;name&quot;:&quot;调查-20180806036&quot;,&quot;num&quot;:0,&quot;countnum&quot;:0,&quot;tid&quot;:3,&quot;createtime&quot;:&quot;1533548351&quot;,&quot;status&quot;:0})"></div><p class="mui-ellipsis base_grey content_p right-tag font12 ">未开始</p></div><div class="left-div"><p class="mui-ellipsis base_dark_grey font14 cell-title"><span class="message_title">调查-20180806036</span> </p><p class="mui-ellipsis base_grey font14 content_p cell-subtitle"><span class="file_submit_time">2018-08-06 17:39</span></p></div></div></a></li> -->
			</ul>
		</div>
		<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button"  onclick="refreshData()"class="mui-btn mui-btn-outlined">
				重新加载
			</button>
		</div>
		<!--删除微博-->
		<div id="logout" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title" id="deleInfo">确定删除调查？</strong>
				</div>
				<div class="weui_dialog_ft">
					<a href="javascript:cancel();" class="weui_btn_dialog default" style="color:#18b4ed">取消</a>
					<a  href="javascript:confirm();" class="weui_btn_dialog primary" style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/activityBottomPopup.js"></script>
	<script type="text/javascript">
		var page = 1;
		var rows = 10;
		var refreshCount = 0;
		var sid = '';
		var firstLoad = true;
		var itemIndex = "";
		apiready = function() {
			loadNewData();
			setRefreshHeader();
			setPullUpRefresh();
			receNotifi();
			$('#deleInfo').text('确定删除' + ludongJudge() + '？');
			sendBuriedNotifi('0', '老师端调查列表页', '197')
		};
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

		function receNotifi() {
			api.addEventListener({
				name : 'refreshQusetionData'
			}, function(ret, err) {
				refreshData();
			});
			api.addEventListener({
				name : 'RerfeshThList'
			}, function(ret, err) {
				refreshData();
			});
			api.addEventListener({
				name : 'pushMessage_classroomMessage'
			}, function(ret, err) {
				var notifiJid = ret.value.jid;
				if (notifiJid == $api.getStorage('cfnetppjxid')) {
					var DC_TYPE = ret.value.type;
					if (DC_TYPE == 10010) {
						loadNewData();
					}
				}
			});
		}

		//是否是鲁东智慧课堂
		function ludongJudge() {
			//读取消息推送
			var jid = $api.getStorage('cfnetppjxid');
			if (jid != 425) {//非鲁东智能课堂
				return '调查'
			} else {
				return '投票'
			}
		}

		//下拉刷新
		function setRefreshHeader() {
			api.setRefreshHeaderInfo({
				visible : true,
				bgColor : '#ccc',
				textColor : '#fff',
				textDown : '下拉刷新...',
				textUp : '松开刷新...',
				showTime : true
			}, function(ret, err) {
				loadNewData();
			});
		}

		// 上拉加载
		function setPullUpRefresh() {
			api.addEventListener({
				name : 'scrolltobottom'
			}, function(ret, err) {
				if (refreshCount >= rows) {
					loadMoreData();
				}
			});
		}

		function loadNewData() {
			page = 1;
			loadData();
		}

		function loadMoreData() {
			page++;
			loadData();
		}

		//获取数据
		function loadData() {
			if (firstLoad == true) {
				showProgress();
				firstLoad = false;
			}
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				page : page,
				rows : rows,
				tid : 3,
				cid : api.pageParam.cid,
				pid : api.pageParam.pid,
			};
			cfnetppPOST(url_activeList, params, true, function(data, status) {
				api.hideProgress();
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
						var listdata = data.data;
						if (listdata != '' && listdata.constructor == Array && listdata.length > 0) {
							$('#noData').hide();
							$('#noNet').hide();
							$('#mian').show();
							refreshCount = listdata.length;
							writelist(listdata, refreshCount);
						} else {
							if (page == 1) {
								$('#noData').show();
								$('#noNet').hide();
							}
						}
					} else if (data.code = 108) {
						if (page == 1) {
							$('#noData').show();
							$('#noNet').hide();
							$('#stulist').html('');
						}
					} else {
						if (page == 1) {
							$('#noData').show();
							$('#noNet').hide();
							$('#stulist').html('');
						}
					}
				} else {
					if (page > 1) {
						page--;
						refreshCount = rows;
						api.toast({
							msg : '网络异常'
						});
					} else {
						$('#noData').hide();
						$('#noNet').show();
						$('#stulist').html('');
					}
				}
			});
		}

		function refreshData() {
			firstLoad = true;
			loadNewData();
		}

		function writelist(listdata, len) {
			var htmlsdata = '';
			for (var i = 0; i < len; i++) {
				var data = listdata[i];
				var type = data.status;
				var num = parseInt(data.num);
				var countnum = parseInt(data.countnum);
				var delethtml = '';
				var status = '';
				var starttime = data.starttime;
				var timeString = '';
				if (starttime == null) {
					timeString = timeWithStamp3(data.createtime);
				} else {
					timeString = timeWithStamp3(starttime);
				}
				var DataArr = JSON.stringify(data).replace(/"/g, '&quot;');
				if (type == 0) {//未开始
					status = '未开始';
					delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
				} else if (type == 1) {//进行中
					status = '进行中';
					delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
				} else if (type == 2) {//已经
					status = '已关闭';
					delethtml = '<p class="mui-ellipsis base_grey content_p right-tag  font12">' + num + '/' + countnum + '提交' + '</p>'
				}
				var htmls = '<li class="mui-table-view-cell mui-media" where_type="' + data.status + '"  id="' + data.id + '"  onclick="openwin(this,' + DataArr + ')">' + '<a  href="javascript:;" )">' + '<img class="mui-media-object mui-pull-left" src="../../icon/icon_research.png" >' + '<div class="mui-media-body">' + '<div class="right-div">' + '<div class="discuss-del-div">' + delethtml + '</div>' + '<p class="mui-ellipsis base_grey content_p right-tag  font12  ">' + status + '</p>' + '</div>' + '<div class="left-div">' + '<p class="mui-ellipsis base_dark_grey font14 cell-title">' + '<span class="message_title">' + data.name + '</span>  ' + '</p>' + '<p class="mui-ellipsis base_grey font14 content_p cell-subtitle">' + '<span class="file_submit_time">' + timeString + '</span>' + '</p>' + '</div>' + '</div>' + '</a>' + '</li>';
				htmlsdata = htmlsdata + htmls;
			}
			if (page == 1) {
				$('#list_day').html(htmlsdata);
			} else {
				$('#list_day').append(htmlsdata);
			}
		}

		//单条数据刷新
		function itemRefresh(i, type, data) {
			var statusStr = "";
			var imgStr = "";
			var id = data.id;
			var DataArr = JSON.stringify(data).replace(/"/g, '&quot;');
			var type = data.status;
			if (type == 0) {//未开始
				statusStr = '未开始';
				imgStr = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
			} else if (type == 1) {//进行中
				statusStr = '进行中';
				imgStr = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
			} else if (type == 2) {//已经
				statusStr = '已关闭';
				imgStr = '<p class="mui-ellipsis base_grey content_p right-tag  font12">' + data.num + '/' + data.countnum + '提交' + '</p>'
			}
			$('#' + id).children('p').eq(0).html('');
			$('#' + id).children('p').eq(0).html(statusStr);
			$('#' + id).attr("where_type", type);
			$('#' + id).children('.discuss-del-div').html('');
			$('#' + id).children('.discuss-del-div').html(imgStr);
		}

		function deletquestion(tid, i) {
			$("#logout").show();
			sid = tid;
			itemIndex = i;
		}

		function openwin(obj, data) {
			sendBuriedNotifi('1', '老师端调查列表页', '197')
			var item = data;
			//1是进行中，2是关闭，0就是未开始
			var type = $(obj).attr("where_type");
			if (type == 2 || type == 1) {
				api.openWin({useWKWebView:true,
					name : 'Teacher_ResearchListDetail',
					url : 'Teacher_ResearchListDetail.html',
					pageParam : {
						id : data.id,
						name : data.name,
						sourceurl : window.location.pathname,
						sourcetitle : document.title
					},
					slidBackEnabled : false,
					reload : true
				});
			} else if (type == 0) {
				api.openWin({useWKWebView:true,
					name : 'Teacher_EditResearchListDetailWin',
					url : 'Teacher_EditResearchListDetailWin.html',
					pageParam : {
						id : data.id,
						name : data.name,
						type1 : 5,
						classname : data.classname,
						sourceurl : window.location.pathname,
						sourcetitle : document.title
					},
					slidBackEnabled : false,
					reload : true
				});
			}
		}

		function openPopu(i, type, data) {
			event.stopPropagation();
			if ($(".popu_img").eq(i).attr("src") == "../../image/icon_bewrite_down.png") {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_up.png");
			} else {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_down.png");
			}
			var pTag1 = new Object();
			var pTag2 = new Object();
			var pTag3 = new Object();
			if (type == 0) {//未开始
				pTag3 = {
					imgUrl : '../../image/icon_activity_start.png',
					title : '开始'
				}
			} else if (type == 1) {//进行中
				pTag1 = {
					imgUrl : '../../image/icon_activity_del_disabled.png',
					title : '删除',
					textcolor : '#999999'
				}
				pTag2 = {
					imgUrl : '../../image/icon_activity_edit_disabled.png',
					title : '编辑',
					textcolor : '#999999'
				}
				pTag3 = {
					imgUrl : '../../image/icon_activity_end.png',
					title : '结束'
				}
			} else if (type == 2) {
				pTag1 = {
					imgUrl : '../../image/icon_activity_del_disabled.png',
					title : '删除',
					textcolor : '#999999'
				}
				pTag2 = {
					imgUrl : '../../image/icon_activity_edit_disabled.png',
					title : '编辑',
					textcolor : '#999999'
				}
				pTag3 = {
					imgUrl : '../../image/icon_activity_end.png',
					title : '已结束'
				}
			}
			/*
			 * @param topTitle标题
			 * @param pTag1标签1 不传显示默认
			 * @param pTag2标签2 不传显示默认
			 * @param pTag3标签3 不传显示默认
			 * @param imgUrl图片路径
			 * @param title标签名称
			 *  return tag 0点击背景 1点击tag1 2点击tag2 3点击tag3 4点击取消*/
			var popup = new activityBottomPopupObjc();
			popup.openBottomPopup({
				topTitle : data.name,
				pTag1 : pTag1,
				pTag2 : pTag2,
				pTag3 : pTag3
			}, function(tag) {
				//				alert(tag);
				JudgeTypeOpen(i, tag, type, data)
				popup.closeBottomPopup();
			});
		}

		function JudgeTypeOpen(i, tag, type, data) {
			switch(tag) {
				case 1:
					if (type == 0) {//未开始状态才可删除
						deletquestion(data.id, i)
					}
					break;
				case 2:
					if (type == 0) {//未开始
						edit(data)
					}
					break;
				case 3:
					if (type == 0) {
						start(i, data.id, data)
					} else if (type == 1) {
						end(i, data.id, data)
					}
					break;
				default:
			}
			if ($(".popu_img").eq(i).attr("src") == "../../image/icon_bewrite_down.png") {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_up.png");
			} else {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_down.png");
			}
		}

		//取消
		function cancel() {
			$("#logout").hide();
		}

		//确定
		function confirm() {
			delet();
			$("#logout").hide();
		}

		//开始活动
		function start(i, iid, Arrdata) {
			var params = {
				tid : 3,
				iid : iid,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				action : 'start',
			}
			cfnetppPOST(url_actionDosign, params, true, function(data, status) {
			   SendBusinessOperationsLogNotifi('老师端调查开始', '197', params, params, '', data, '老师端调查开始接口', '197-01')
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						itemRefresh(i, '1', Arrdata)
					} else {
						ShowToast('开启失败');
					}
				}
			})
		}

		//结束活动
		function end(i, iid, data) {
			var params = {
				tid : 3,
				iid : iid,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				action : 'end',
			}
			cfnetppPOST(url_actionDosign, params, true, function(data, status) {
			  SendBusinessOperationsLogNotifi('老师端调查结束', '197', params, params, '', data, '老师端调查结束接口', '197-03')
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						itemRefresh(i, '2', data)
					} else {
						ShowToast('结束失败');
					}
				}
			})
		}

		//编辑活动
		function edit(data) {
			api.openWin({useWKWebView:true,
				name : 'Teacher_EditResearchListDetailWin',
				url : 'Teacher_EditResearchListDetailWin.html',
				pageParam : {
					id : data.id,
					name : data.name,
					type1 : 5,
					classname : data.classname,
					sourceurl : window.location.pathname,
					sourcetitle : document.title
				},
				slidBackEnabled : false,
				reload : true
			});
		}

		//删除活动
		function delet() {
			var params = {
				aid : sid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
			}
			cfnetppPOST(url_Delactive, params, true, function(data, status) {
			   SendBusinessOperationsLogNotifi('老师端调查删除', '197', params, params, '', data, '老师端调查删除接口', '197-02')
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						$('#' + sid).remove();
						if ($('#list_day').html() == '') {
							$('#noData').show();
							$('#noNet').hide();
						}
					} else {
						ShowToast('删除失败');
					}
				}
			})
		}
	</script>
</html>